<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>房间类型管理 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <style type="text/css">
        .mask {
            position: absolute;
            top: 0px;
            filter: alpha(opacity=60);
            background-color: white;
            z-index: 100000;
            left: 0px;
            opacity: 0.01;
            -moz-opacity: 0.01;
            display: none;
        }
    </style>
</head>
<body>
<div id="mask" class="mask"></div>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">
    <input type="hidden" id="Room_typeId"/>
    <div class="layui-form-item">
        <label class="layui-form-label">类型名称</label>
        <div class="layui-input-inline">
            <input type="text" id="Room_typeName" lay-verify="required" placeholder="请填写类型名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单日价格</label>
        <div class="layui-input-inline">
            <input type="text" id="Room_typePrice" lay-verify="required|validateMoney"
                   placeholder="请输入价格"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">楼层</label>
        <div class="layui-input-inline">
            <input type="text" id="Room_typeFloors" lay-verify="required|number"
                   placeholder="请输入楼层" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">面积(m²)</label>
        <div class="layui-input-block">
            <input type="text" id="Room_typeSize" lay-verify="required|mm2"
                   placeholder="请输入房间面积(m²)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可住人数</label>
        <div class="layui-input-block">
            <input type="text" id="Room_typePeoplenumber" lay-verify="required|number"
                   placeholder="请输入可住人数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否有窗</label>
        <div class="layui-input-block">
            <input type="radio" name="iswindow" value="1" title="有" checked>
            <input type="radio" name="iswindow" value="0" title="无">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">免费WiFi</label>
        <div class="layui-input-block">
            <input type="radio" name="iswifi" value="1" title="有" checked>
            <input type="radio" name="iswifi" value="0" title="无">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">高速宽带</label>
        <div class="layui-input-block">
            <input type="radio" name="isweb" value="1" title="有" checked>
            <input type="radio" name="isweb" value="0" title="无">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">床数</label>
        <div class="layui-input-inline">
            <input type="text" id="Room_typeBednumber" lay-verify="required|number"
                   placeholder="请输入床数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label">预设类型</label>-->
    <!--        <div class="layui-input-inline">-->
    <!--            <select id="Room_typeRoom_product_typeId" lay-filter="Room_typeRoom_product_typeId">-->

    <!--            </select>-->
    <!--        </div>-->
    <!--    </div>-->
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="employee-submit" id="employee-submit"
               value="确认添加">
        <input type="button" lay-submit lay-filter="employee-edit" id="employee-edit"
               value="确认编辑">
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js"></script>
<script src="../../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
    //显示遮罩层
    function showMask() {
        $("#mask").css("height", $(document).height());
        $("#mask").css("width", $(document).width());
        $("#mask").show();
    }

    //隐藏遮罩层
    function hideMask() {
        $("#mask").hide();
    }
</script>
<script>
    // //下拉框初始化
    // $.ajax({
    //     url: '/roomType/toAdd',
    //     type: 'post',
    //     dataType: 'json',
    //     data: {},
    //     async: false,//设置阻断
    //     success: function (data) {
    //         if (data.status != 200) {
    //             layer.msg('查询失败！');
    //         } else {
    //             //将下拉框中添加数据
    //             var modelList = data.room_product_type;
    //             if (modelList && modelList.length != 0) {
    //                 for (var i = 0; i < modelList.length; i++) {
    //                     var option = "<option value=\"" + modelList[i].id + "\"";
    //                     option += ">" + modelList[i].name + "</option>";  //动态添加数据
    //                     $('#Room_typeRoom_product_typeId').append(option);
    //                 }
    //             }
    //         }
    //     }
    // });

    //根据父级页面判断，如果是修改，则添加默认值
    if (parent.Room_typeType == "toUpdate") {
        $.ajax({
            url: parent.toUpdateURL,
            type: 'post',
            dataType: 'json',
            async: false,//设置阻断
            data: {"id": parent.Room_typeId},
            success: function (data) {
                $("#Room_typeId").val(parent.Room_typeId);
                //重新渲染表单元素
                $("#Room_typeName").val(parent.Room_Name)
                // $("#Room_typeIcon").val(data.data.icon)
                $("#Room_typePrice").val(data.data.price)
                $("#Room_typeFloors").val(data.data.floors)
                $("#Room_typeSize").val(data.data.size)
                $("#Room_typePeoplenumber").val(data.data.peoplenumber)
                $("#Room_typeBednumber").val(data.data.bednumber)
                $("input[name=iswifi][value='0']").attr("checked", data.data.iswifi == 0 ? true : false)
                $("input[name=iswindow][value='0']").attr("checked", data.data.iswindow == 0 ? true : false)
                $("input[name=isweb][value='0']").attr("checked", data.data.isweb == 0 ? true : false)
                // $("input[name=iswifi][type=radio][value=" + data.data.iswifi + "]").attr("checked", true),
                // $("input[name=iswindow][type=radio][value=" + data.data.iswindow + "]").attr("checked", true),
                // $("input[name=isweb][type=radio][value=" + data.data.isweb + "]").attr("checked", true)

                //选中下拉框中的option
                // $("#Room_typeRoom_product_typeId").find("option[value=" + data.data.room_product_type_id + "]").prop("selected", true)

            }
        });

    }
    //layui配置
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form;
        form.render();
        form.verify({
            validateMoney: [
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/  //正则表达式
                , '金额输入有误'  //提示信息
            ],
            mm2: [
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/  //正则表达式
                , '面积输入有误'  //提示信息
            ]
        });
        //监听提交
        form.on('submit(employee-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //获取id，若无则改为0
            var id = $("#Room_typeId").val();
            if (id == null || id == "") id = 0;
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: parent.Room_typeURL,
                type: 'post',
                dataType: 'json',
                data: {
                    "id": id,
                    "name": $("#Room_typeName").val(),
                    "price": $("#Room_typePrice").val(),
                    "floors": $("#Room_typeFloors").val(),
                    "size": $("#Room_typeSize").val(),
                    "peoplenumber": $("#Room_typePeoplenumber").val(),
                    "bednumber": $("#Room_typeBednumber").val(),
                    "isweb": $('input[name="isweb"]').filter(':checked').val(),
                    "iswindow": $('input[name="iswindow"]').filter(':checked').val(),
                    "iswifi": $('input[name="iswifi"]').filter(':checked').val()

                    // "room_product_type_id": $("#Room_typeRoom_product_typeId").val()
                },
                success: function (data) {
                    parent.layer.msg(data.msg, {icon: data.icon, zIndex: layer.zIndex + 100});
                }
            });
            parent.layui.table.reload('Room_typeTable'); //重载表格
            parent.layer.close(index); //再执行关闭
        });
    })


</script>
</body>
</html>